﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.ComponentModel;
namespace CoreData
{
    public class Staff
    {
        public long ID { get; set; }
        public string StaffGuidID { get; set; }
        [Description("Mã nhân viên")]
        public string Code { get; set; }
        [Description("Tên nhân viên")]
        public string Name { get; set; }
        [Description("Ngày sinh")]
        public DateTime BirthDay { get; set; }
        public DateTime CreateDate { get; set; }
        public DateTime ModifiedDate { get; set; }
        [Description("Địa chỉ thường trú")]
        public string Address1 { get; set; }
        [Description("Địa chỉ tạm trú")]
        public string Address2 { get; set; }
        [Description("Số điện thoại")]
        public string Phone { get; set; }
        [Description("CMND")]
        public string IndentityCard { get; set; }
        [Description("Giới tính")]
        public string Sex { get; set; }
        [Description("Chức vụ")]
        public string Regency { get; set; }
        [Description("Ngày vào làm")]
        public DateTime StartDateWork { get; set; }
        [Description("Ngày ký hợp đồng")]
        public DateTime DateOfSignContract { get; set; }
        [Description("Số sổ bảo hiểm xã hội")]
        public string SocialInsuranceNumber { get; set; }
        [Description("Ghi chú")]
        public string Note { get; set; }

        public Staff()
        {
            StaffGuidID = Guid.NewGuid().ToString();
            Code = "";
            Name = "";
            Address1 = "";
            Address2 = "";
            Phone = "";
            IndentityCard = "";
            Sex = "";
            Regency = "";
            SocialInsuranceNumber = "";
            Note = "";
            StartDateWork = DateTime.Now;
            DateOfSignContract = DateTime.Now;
        }

        static Staff DynamicCast<T>(object row_data, object row_header) where T : Staff
        {
            // row_data : DataRow
            // row_header : DataColumnCollection
            Staff ret = new Staff();
            DataRow dt = (DataRow)row_data;

            foreach (DataColumn column in (DataColumnCollection)row_header)
            {
                switch (column.ColumnName)
                {
                    case "ID":
                        ret.ID = ConvertObject.ToLong(dt[column]);
                        break;
                    case "StaffGuidID":
                        ret.StaffGuidID = ConvertObject.ToString(dt[column]);
                        break;
                    case "Code":
                        ret.Code = ConvertObject.ToString(dt[column]);
                        break;
                    case "Name":
                        ret.Name = ConvertObject.ToString(dt[column]);
                        break;
                    case "BirthDay":
                        ret.BirthDay = ConvertObject.ToDateTime(dt[column]);
                        break;
                    case "CreateDate":
                        ret.CreateDate = ConvertObject.ToDateTime(dt[column]);
                        break;
                    case "ModifiedDate":
                        ret.ModifiedDate = ConvertObject.ToDateTime(dt[column]);
                        break;
                    case "Address1":
                        ret.Address1 = ConvertObject.ToString(dt[column]);
                        break;
                    case "Address2":
                        ret.Address2 = ConvertObject.ToString(dt[column]);
                        break;
                    case "Phone":
                        ret.Phone = ConvertObject.ToString(dt[column]);
                        break;
                    case "IndentityCard":
                        ret.IndentityCard = ConvertObject.ToString(dt[column]);
                        break;
                    case "Sex":
                        ret.Sex = ConvertObject.ToString(dt[column]);
                        break;
                    case "Regency":
                        ret.Regency = ConvertObject.ToString(dt[column]);
                        break;
                    case "StartDateWork":
                        ret.StartDateWork = ConvertObject.ToDateTime(dt[column]);
                        break;
                    case "DateOfSignContract":
                        ret.DateOfSignContract = ConvertObject.ToDateTime(dt[column]);
                        break;
                    case "SocialInsuranceNumber":
                        ret.SocialInsuranceNumber = ConvertObject.ToString(dt[column]);
                        break;
                    case "Note":
                        ret.Note = ConvertObject.ToString(dt[column]);
                        break;

                    default:
                        break;
                }
            }

            return ret;
        }

    }
}
